<?php

/**
 * Controller.php
 */
class Controller extends CController {

    public $breadcrumbs = array();
    public $menu = array();
    public $description;
    public $keywords;

    public function __construct($id, $module = null) {
	parent::__construct($id, $module);

//        cs()->registerCoreScript('jquery');
	/*
	 * set timezone depend on ip
	 */
//	if (user()->id && user()->getModel()->status == User::STATUS_ACTIVE) {
//	    $timezone = Yii::app()->cache->get('time_zone_' . user()->id);
//	    if ($timezone === false) {
//
//		$ip = $_SERVER['REMOTE_ADDR']; // means we got user's IP address 
//		$ch = curl_init('http://smart-ip.net/geoip-json/' . $ip);
//		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//		$json = curl_exec($ch);
//		$ipData = json_decode($json, true);
//		if ($ipData['timezone']) {
//		    $timezone = $ipData['timezone'];
//		    //save cache in one month
//		    Yii::app()->cache->set('time_zone_' . user()->id, $ipData['timezone'], 2592000);
//		}
//	    }
//	    
//	    if ($timezone) {
//		date_default_timezone_set($timezone);
//	    }
//	}
    }

    /**
     * function run after layout loaded
     * @param type $view
     * @param type $output
     */
    public function afterRender($view, &$output) {

	Yii::app()->clientScript->registerMetaTag($this->description, 'description');
	Yii::app()->clientScript->registerMetaTag($this->keywords, 'keywords');
    }

}
